<?php

class MatchTypeAPIController extends \BaseController {

	/**
	 * Controller constructor
	 */
	public function __construct() {
	}
	
	/**
	 * Display a listing of match types.
	 *
	 * @return Response
	 */
	public function index()
	{
		return Response::json(MatchType::all());
	}


	/**
	 * Store a newly created match type in storage.
	 *
	 * @return Response
	 */
	public function store()
	{
		$newMatchType = Input::json();
	
		$matchType = new MatchType();
		$matchType->name = $newMatchType->get('name');
		$matchType->totalPlayers = $newMatchType->get('totalPlayers');
		$matchType->versus = $newMatchType->get('versus');
		$matchType->save();
	
		return Response::json($matchType);
	}


	/**
	 * Display the specified match type.
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function show($id)
	{
		$matchType = MatchType::find($id);
		if(is_null($matchType)){
			return Response::json('MatchType not found', 404);
		} else {
			return Response::json($matchType);
		}
	}


	/**
	 * Update the specified match type in storage.
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function update($id)
	{
		$matchType = MatchType::find($id);
		if(is_null($matchType)){
			return Response::json('MatchType not found', 404);
		}
		$matchType->name = $updateMatchType->get('name');
		$matchType->totalPlayers = $updateMatchType->get('totalPlayers');
		$matchType->versus = $updateMatchType->get('versus');
		$matchType->save();
	
		return Response::json($matchType);
	}


	/**
	 * Remove the specified match type from storage.
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function destroy($id)
	{
		$matchType = MatchType::find($id);
	
		if(is_null($matchType))
		{
			return Response::json('MatchType not found', 404);
		}
		$deletedMatchType = $matchType;
		$matchType->delete();
		return Response::json($deletedMatchType);
	}
	
}
